{% extends 'base_children.html' %}

{% load mytags %}
{% block content %}
    <div class="layui-row larryms-panel ">
        <form action="{% url 'cmdb_xunihost_edit' %}" class="layui-form layui-form-pane" method="post" id="demoAddForm">
            {% csrf_token %}
            <input class="layui-input" name="id" value="{{ host.id }}" type="text" hidden>
            <div class="layui-form-item">
                <div class="layui-form-inline">
                    <label class="layui-form-label">主机名</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="hostname" value="{{ host.hostname }}" type="text" disabled>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">访问IP</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="ip" value="{{ host.ip }}" type="text" disabled>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">宿主机</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="hostserver" value="{{ host.hostserver | default_if_none:"" }}"
                               type="text">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">端口</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="port" value="{{ host.port }}" type="text" disabled>
                    </div>
                </div>
            </div>
  <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">用户</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="username" value="{{ host.username }}" type="text" disabled>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="passwd" value="{{host.passwd|jiemi }}"
                               type="text">
                    </div>
                </div>

            </div>

            <div class="layui-col-md6">

                <div class="layui-form-item">

                    <div class="layui-inline">
                        <label class="layui-form-label">机房</label>
                        <div class="layui-input-block">
                            <select name="idc">
                                <option value=""></option>
                                {% for ss in idc %}
                                    {% ifequal ss.id host.idc_id %}
                                        <option value="{{ ss.id }}" selected> {{ ss.name }}</option>
                                    {% else %}
                                        <option value="{{ ss.id }}"> {{ ss.name }}</option>
                                    {% endifequal %}
                                {% endfor %}
                            </select>
                        </div>
                    </div>


                    <div class="layui-inline">
                        <label class="layui-form-label">ssh登陆</label>
                        <div class="layui-input-block">
                            <select name="ssh_status">
                                {% ifequal 0|int2str host.ssh_status %}
                                    <option value="0" selected>不可登陆</option>
                                    <option value="1"> 可ssh登陆</option>
                                {% else %}
                                    <option value="0">不可登陆</option>
                                    <option value="1" selected> 可ssh登陆</option>

                                {% endifequal %}

                            </select>
                        </div>
                    </div>

                </div>

            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">使用人</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="useuser" value="{{ host.useuser |default_if_none:'' }}"
                               type="text">
                    </div>

                </div>


                <div class="layui-inline">
                    <label class="layui-form-label">用途</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="purpose" value="{{ host.purpose }}" type="text">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">上线日</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="up_date" value="{{ host.onlinedate }}" id='up_date' placeholder=""
                               type="text">
                    </div>
                </div>


            </div>


            <div class="larryms-layer-btn " align="center">
                {#                    <a class="layui-btn layui-btn layui-btn-sm  layui-btn-normal" id="testconn">测试连接</a>#}
                <a class="layui-btn layui-btn layui-btn-sm left" lay-submit="" lay-filter="demoadd"
                   id="submitAdd">确定</a>
                <a class="layui-btn layui-btn layui-btn-sm  layui-btn-danger" id="resetAdd">重置</a>
                <a class="layui-btn layui-btn layui-btn-sm  layui-btn-danger" id="closeAdd">关闭</a>
            </div>


        </form>
    </div>

{% endblock %}
{% block self_foot %}
    <script type="text/javascript">
        layui.config({
            version: "2.0.8",
            base: '/static/larryms/',
            layertype: 2, //iframe内层弹窗类型不显示返回首页
            rightMenu: false // false关闭，设置为custom时使用自定义，不使用默认menu
        }).extend({
            larry: 'js/base'
        }).use(['larry', 'layer','jquery' ,'table','form', 'laydate'], function () {
            var $ = layui.$,
                larry = layui.larry,
                table = layui.talbe,
                layer=layui.layer,
                larryms = layui.larryms,
                laydate = layui.laydate,
                form = layui.form;

            var curIfr = parent.layer.getFrameIndex(window.name);
            $('#resetAdd').on('click', function () {
                $('#demoAddForm')[0].reset();
            });
            $('#closeAdd').on('click', function () {
                parent.layer.close(curIfr);
            });
            laydate.render({
                elem: '#up_date'
                , value: '{{ data.start_date|date:'Y-n-d' }}', format: 'yyyy-MM-dd', isInitValue: true
            });
            laydate.render({
                elem: '#down_date'
                , value: '{{ data.end_date|date:'Y-n-d' }}', format: 'yyyy-MM-dd', isInitValue: true
            });

            form.on('submit(demoadd)', function (data) {
                $.post(data.form.action, data.field, function (res) {
                    if (res.code == 0) {
                        larryms.msg(res.msg);
                        {#parent.table.reload('demo', {}); //刷新tableid ,中括号是针对分页，刷新某一页的数据时使用#}
                        parent.layer.close(curIfr);

                        {#// $('#demoAddForm')[0].reset();继续添加注销上一段#}
                        {#larryms.msg(res.msg, {time: 550}, function () {#}
                        {#    parent.table.reload('demo', {});#}
                        {#    parent.layer.close(curIfr);#}
                        {# } #}


                }else if (res.code == 911) {
                        larryms.msg(res.msg);
                    } else if (res.code == 500) {
                        larryms.msg(res.msg);
                    }
                });
                return false;
            });

        });


    </script>

{% endblock %}